// Copyright (c) 2021 Presto Labs Pte. Ltd.
// Author: jhkim

#pragma once

#include <regex>
#include "coin2/strategy/linear_model/calc_util.h"

namespace coin2::strategy::linear_model {

struct SkipManager {

void AddFile(const std::string& skip_config_filepath) {
  if (!skip_config_filepath.empty()) {
    std::ifstream in(skip_config_filepath);
    CHECK_THROW(in.is_open());
    std::string str((std::istreambuf_iterator<char>(in)),
                    std::istreambuf_iterator<char>());
    LmSkipConfig skip_config;
    google::protobuf::util::JsonStringToMessage(str, &skip_config);
    in.close();
    for (const auto& skip_config : skip_config.skip_configs()) {
      tfeed_skip_quotes[skip_config.quote()] = skip_config.tfeed_skip_quote();
    }
  }
}

bool BanByQuoteSize(
    const coin2::exchange::base::symbology::IProductHolder& pholder,
    double price,
    double qty) const {
  auto it = tfeed_skip_quotes.find(pholder.product().quote().currency());
  if (it != tfeed_skip_quotes.end()) {
    double quote_value = GetQuoteFromPq(pholder, price, qty);
    return quote_value < it->second;
  }
  return false;
}

bool empty() const {
  return tfeed_skip_quotes.empty();
}

std::unordered_map<std::string, double> tfeed_skip_quotes;
};

}  // namespace coin2::strategy::linear_model
